home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
endo
/
file.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-03
|
3KB
|
92 lines
/*************************************************************************
* *
* Copyright (c) 1992, 1993 Ronald Joe Record *
* *
* All rights reserved. No part of this program or publication may be *
* reproduced, transmitted, transcribed, stored in a retrieval system, *
* or translated into any language or computer language, in any form or *
* by any means, electronic, mechanical, magnetic, optical, chemical, *
* biological, or otherwise, without the prior written permission of: *
* *
* Ronald Joe Record (408) 458-3718 *
* 212 Owen St., Santa Cruz, California 95062 USA *
* *
*************************************************************************/
#include <stdio.h>
#include "x.h"
/* Store color pics in PPM format and monochrome in PGM */
void
save_to_file(pix, w, h)
Pixmap pix;
int w, h;
{
FILE *outfile;
/* FILE *pickfile; */
unsigned char c;
XImage *ximage;
static int i,j;
struct Colormap {
unsigned char red;
unsigned char green;
unsigned char blue;
};
struct Colormap *colormap=NULL;
if (colormap)
free(colormap);
if ((colormap=
(struct Colormap *)malloc(sizeof(struct Colormap)*numcolors))==NULL){
fprintf(stderr,"Error malloc'ing colormap array.\n");
Cleanup();
exit(-1);
}
outfile = fopen(outname,"w");
/* pickfile = fopen("pick.out", "w"); */
if(!outfile) {
perror(outname);
Cleanup();
exit(-1);
}
ximage=XGetImage(dpy, pix, 0, 0, w, h, AllPlanes, ZPixmap);
if (displayplanes > 1) {
for (i=0;i<numcolors;i++) {
colormap[i].red=(unsigned char)(Colors[i].red >> 8);
colormap[i].green=(unsigned char)(Colors[i].green >> 8);
colormap[i].blue =(unsigned char)(Colors[i].blue >> 8);
}
fprintf(outfile,"P%d %d %d\n",6,w,h);
}
else
fprintf(outfile,"P%d %d %d\n",5,w,h);
fprintf(outfile,"# settle=%d dwell=%d delta=%lf cdelta=%lf\n",
settle, dwell, delta, cdelt);
fprintf(outfile,"# min_x=%lf a_rng=%lf max_x=%lf\n",min_x,x_range,max_x);
fprintf(outfile,"# min_y=%lf b_rng=%lf max_y=%lf\n",min_y,y_range,max_y);
for (i=0;i<MAXPARAMS/2;i++)
fprintf(outfile,"# params[%d]=%lf params[%d]=%lf\n",
i,params[i],2*i,params[2*i]);
fprintf(outfile,"# Map name = %s mapindex=%d\n",
Mapnames[mapindex], mapindex);
fprintf(outfile,"# find=%d portrait=%d critical=%d attractors=%d\n",
find, portrait, critical, attractors);
fprintf(outfile,"# lyap=%d p1=%d p2=%d start_x=%lf start_y=%lf\n",
lyap, p1, p2, start_x, start_y);
fprintf(outfile,"%d\n",numcolors-1);
for (j=0;j<h;j++)
for (i=0;i<w;i++) {
c = (unsigned char)XGetPixel(ximage,i,j);
if (displayplanes > 1)
fwrite((char *)&colormap[c],sizeof colormap[0],1,outfile);
else
fwrite((char *)&c,sizeof c,1,outfile);
/* fwrite((char *)&c,sizeof c,1,pickfile); */
}
fclose(outfile);
/* fclose(pickfile); */
}